/**
 * file api
 */
import $http from '../../http/http'

/**
 * 下载nice.pptx
 */
export const downloadFile = (fileName, data) => {
    return $http({
        method: "post",
        url: "fileOperations/download",
        data,
        responseType: 'blob'
    }).then(res => {
        if (!res) {
            return;
        }

        const blob = new Blob([res])
        if ('download' in document.createElement('a')) { // 非IE下载
            const elink = document.createElement('a')
            elink.download = fileName
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href) // 释放URL 对象
            document.body.removeChild(elink)
        } else { // IE10+下载
            navigator.msSaveBlob(blob, fileName)
        }
    });
}

export const uploadFile = (formData) => {
    return $http.post("fileOperations/multiFilesUpload1", formData, {
        "Content-Type": "multipart/form-data"
    });
}